package com.huike.clues.service.Impl;

import com.github.pagehelper.PageInfo;
import com.huike.clues.domain.TbActivity;
import com.huike.clues.mapper.TbActivityMapper;
import com.huike.clues.service.TbActivityService;
import com.huike.common.constant.HttpStatus;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.uuid.UUID;
import com.huike.common.utils.uuid.UUIDUtils;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class TbActivityServiceImpl implements TbActivityService {
    @Resource
    private TbActivityMapper tbActivityMapper;

    /**
     * 获取所有的活动信息（分页）
     *
     * @param tbActivity
     */
    @Override
    public List<TbActivity> selectActivityList(TbActivity tbActivity) {


        return tbActivityMapper.selectActivityList(tbActivity);


    }

    /**
     * 通过Id删除活力信息
     *
     * @param ids
     */
    @Override
    public void deleteByIds(List<Integer> ids) {
        tbActivityMapper.deleteByIds(ids);
    }

    /**
     * 通过id查询活动信息
     *
     * @param id
     */
    @Override
    public TbActivity selectById(Long id) {
        return tbActivityMapper.selectById(id);
    }

    /**
     * 修改活动信息
     *
     * @param tbActivity
     */
    @Override
    public void updateActivity(TbActivity tbActivity) {

        tbActivityMapper.updateAndInsert(tbActivity);

    }

    /**
     * 添加活动信息
     *
     * @param tbActivity
     */
    @Override
    public void insertTbActivity(TbActivity tbActivity) {
        LocalDateTime localDateTime = LocalDateTime.now();
        Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
        tbActivity.setCreateTime(date);
        tbActivity.setCode(UUIDUtils.getUUID());
        tbActivity.setStatus("2");
        tbActivityMapper.insertTbActivity(tbActivity);

    }

    /**
     * 通过status查询信息
     *
     * @param status
     * @return
     */
    @Override
    public Integer selectStatus(String status) {

        return tbActivityMapper.selectStatus(status);
    }
}
